#include <stdio.h>
#include <unistd.h>
#include <time.h>
#include <signal.h>
#include <stdlib.h>
#include <stdbool.h>

volatile sig_atomic_t running = 1;

void handle_signal(int sig) {
    running = 0;
    printf("Signal %d received, exiting process...\n", sig);
}

int main() {
    // 设置信号处理器
    signal(SIGINT, handle_signal);
    signal(SIGTERM, handle_signal);

    printf("Simple process started. PID = %d\n", getpid());

    while (running) {
        time_t now = time(NULL);
        printf("Running... current time: %s", ctime(&now));
        sleep(1); // 每秒打印一次
    }

    printf("Process exiting normally.\n");
    return 0;
}

